package com.springboot.erp.controller;

import com.springboot.erp.common.CommonResult;
import com.springboot.erp.entity.Return;
import com.springboot.erp.service.ReturnService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 退货单管理控制器
 * 处理退货单的创建、查询、更新和删除操作
 * @author z551199m
 */
@RestController
@RequestMapping("/sales/return")
@Slf4j
public class ReturnController {

    @Autowired
    private ReturnService returnService;

    /**
     * 创建退货单
     */
    @PostMapping
    public CommonResult createReturn(@RequestBody Return returnOrder) {
        log.info("创建退货单: {}", returnOrder);
        return new CommonResult(0, "success", returnService.createReturn(returnOrder));
    }

    /**
     * 根据ID查询退货单
     */
    @GetMapping("/{id}")
    public CommonResult selectReturnById(@PathVariable Long id) {
        log.info("查询退货单，ID: {}", id);
        return new CommonResult(0, "success", returnService.selectReturnById(id));
    }

    /**
     * 更新退货单信息
     */
    @PutMapping
    public CommonResult updateReturn(@RequestBody Return returnOrder) {
        log.info("更新退货单: {}", returnOrder);
        return new CommonResult(0, "success", returnService.updateReturn(returnOrder));
    }

    /**
     * 删除退货单记录
     */
    @DeleteMapping("/{id}")
    public CommonResult deleteReturn(@PathVariable Long id) {
        log.info("删除退货单，ID: {}", id);
        return new CommonResult(0, "success", returnService.deleteReturn(id));
    }
}